import React, { useRef, useState } from 'react'
import { View } from '@tarojs/components'
import Taro from '@tarojs/taro'
import AppHeader from '../../../components/app-header/AppHeader'
import CattleInfo from '../../../components/cattleInfo/cattleInfo'
import './selectLivestock.scss'

export default function SelectLivestock() {

  const [cattleInfo, setCattleInfo] = useState(null)

  // 传递给子组件修改牲畜id的方法
  const changeId = (data) => {
    setCattleInfo(data)
  }

  const toMapHome = () => {
    console.log('点击选择');
    // console.log(cattleId);
    // 跳转到地图首页
    Taro.switchTab({
      url: '/pages/netMap/netMap',
      success: (res) => {
        // 通过eventCenter向被打开页面传送数据(所选中的牛只信息)
        Taro.eventCenter.trigger('selectInfo', cattleInfo)
      }
    })
  }


  return (
    <>

      <View className='select-livestock'>
        <AppHeader title='选择牲畜' top='true' ></AppHeader>

        {/* 选择牲畜列表 */}
        <View className='list'>
          <CattleInfo fn={true} changeId={changeId}></CattleInfo>
        </View>

        <View className='botto' onClick={toMapHome}>确定选择</View>

      </View>

    </>
  )
}
